package com.campus.wall.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.campus.wall.R;
import com.campus.wall.base.BaseMvpActivity;
import com.campus.wall.contract.AddMessageContract;
import com.campus.wall.presenter.AddMessagePresenter;

import java.io.File;
import java.io.IOException;

import butterknife.BindView;
import butterknife.OnClick;

public class AddMessageActivity extends BaseMvpActivity<AddMessagePresenter> implements AddMessageContract.View {

    @BindView(R.id.photo)
    ImageView photo;
    @Override
    public int getLayoutId() {
        return R.layout.layout_add_message;
    }

    @OnClick(R.id.btn_back)
    void btn_back(){
        this.finish();
    }


    @Override
    public void initView() {
        mPresenter = new AddMessagePresenter(this);
        mPresenter.attachView(this);

    }

    @OnClick(R.id.takePhoto)
    void takePhoto(){
        Intent intent=new Intent("android.intent.action.GET_CONTENT");
        //选择相册 intent.setType(“audio/*”); //选择音频 intent.setType(“video/*”); //选择视频
        //这是正常的访问系统自带的文件管理器。但是setType只支持单个setType一般是以下这种(以只查看图片文件为例):
        intent.setType("image/*");
        startActivityForResult(intent,100);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==100){
            Uri uri = data.getData();
            photo.setImageURI(uri);
        }


    }

    @Override
    public void onSuccess() {

    }
}
